import socket
import time


HOST = '127.0.0.1'
PORT = 12346
ADDR = (HOST, PORT)


udp_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)   # 创建套接字
udp_server.bind(ADDR)   # 绑定服务器ip


while True:
    print('...waiting for message...')
    data, addr = udp_server.recvfrom(1024)  # 接受数据
    udp_server.sendto(f'[{bytes(time.ctime(), "utf-8")}]{data}'.encode('utf-8'), addr)  # 发送数据
    print('...received from and return to ...', addr)

udp_server.close()